﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using System.Text;

public partial class Ajax_SignEZCA : System.Web.UI.Page
{ 
    protected void Page_Load(object sender, EventArgs e)
    {

        Response.ContentType = "text/plain";
        //获取表单数据
        string cerid = Request["cerid"].ToString();

        string signdata = Request["UserSignedData"]; //从页面表单传入的签名值
        signdata = signdata.Replace(' ', '+');
        string initdata = Request["initdata"]; //从页面表单传入的原文
        initdata = "=?UTF-8?B?" + Convert.ToBase64String(Encoding.UTF8.GetBytes(initdata)) + "?=";
        string SN = Request["sn"]; //从页面表单传入的原文


        //调用webservice进行签名数据验证和存储
        EZCAService.SignatureServerWebServicePortTypeClient sw = new EZCAService.SignatureServerWebServicePortTypeClient();
        string ret = sw.VD_DataSaveByP1(Guid.NewGuid().ToString(), initdata, signdata, SN);
        //返回错误异常处理
        string error = "";
        if (ret.Equals("10001"))
        {
            error = "签名存储失败";
        }
        else if (ret.Equals("10002"))
        {
            error = "签名数据验证失败";
        }
        else if (ret.Equals("10003"))
        {
            error = "证书未在后台注册或已经注销";

        }
        else if (ret.Equals("10004"))
        {
            error = "证书过期或者不是重庆CA颁发的证书";

        }
        else if (ret.Equals("10006"))
        {
            error = "其他错误，请联系管理员";

        }
        if (!string.IsNullOrEmpty(error))
        {
            Response.Write(new JavaScriptSerializer().Serialize(error));
        }
        else
        {
            Response.Write(new JavaScriptSerializer().Serialize(true));
        }


        Response.End();
    }


}
